<?

/*
Autor: Imanol Iglesias
email: imanolif@gmail.com
*/

define("CURL_TIMEOUT", 4);

class Request
{
	private $session = null;
	private $info;
	private $result;

	public function __construct($url)
	{
		$this->session = curl_init($url);
		curl_setopt($this->session, CURLOPT_TIMEOUT, CURL_TIMEOUT);
	}

	public function exec()
	{
		$this->result = curl_exec($this->session);
		$this->info = curl_getinfo($this->session, CURLINFO_HTTP_CODE);
	}

	public function setHeader($header)
	{
		curl_setopt($this->session, CURLOPT_HTTPHEADER, $header); 
	}

	public function setUserAgent($agent)
	{
		$agents['firefox'] = "Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7";
		curl_setopt($this->session, CURLOPT_USERAGENT, $agents[$agent]);	
	}

	public function getResult()
	{
		return $this->result;
	}

	public function setPOST($post)
	{
		curl_setopt($this->session, CURLOPT_POST, true);
		curl_setopt($this->session, CURLOPT_POSTFIELDS, $post);
	}

	public function setUserAuthentication($user, $password)
	{
		curl_setopt($this->session, CURLOPT_USERPWD, $user.":".$password);
	}

	public function setProxy($url, $post)
	{
		curl_setopt($this->session, CURLOPT_PROXY, $url.":".$port);
	}
	
	public function setOpt($option, $value)
	{
		curl_setopt($this->session, $option, $value);
	}

	public function getInfo()
	{
		return $this->info;
	}

	function __destruct()
	{
		curl_close($this->session);
	}	

}


?>